FROM python:3.7-slim-bullseye

USER root

ENV TZ=UTC

# mirrors.163.com
# RUN sed -i 's/deb.debian.org/mirrors.163.com/g' /etc/apt/sources.list
RUN cat /etc/os-release

RUN echo "deb https://mirrors.tencent.com/debian/ bullseye main non-free contrib\n\
deb-src https://mirrors.tencent.com/debian/ bullseye main non-free contrib\n\
deb https://mirrors.tencent.com/debian-security/ bullseye-security main\n\
deb-src https://mirrors.tencent.com/debian-security/ bullseye-security main\n\
deb https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib\n\
deb-src https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib\n\
deb https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib\n\
deb-src https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib"> /etc/apt/sources.list

# 

RUN apt-get -qq update && apt-get -qq install -y gcc g++ curl ca-certificates libfontconfig libx11-xcb1 libxtst6 libnss3 libasound2 libatk-bridge2.0-0 libgtk-3-0 libopencc-dev opencc  libcurl4-gnutls-dev libpq-dev  python-dev nodejs npm libgnutls28-dev libxml2-dev libxslt-dev zlib1g-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*

COPY --from=99designs/phantomjs:2.1.1 /usr/local/bin/phantomjs /usr/local/bin/phantomjs

ENV OPENSSL_CONF=/etc/ssl/

RUN apt-get clean && apt-get autoclean

# RUN apt-get install -y phantomjs nodejs npm libxtst6 libnss3 libasound2 libx11-xcb1  build-essential ca-certificates g++ --no-install-recommends
ENV PATH=$PATH:/opt/node/bin
WORKDIR "/opt/node"
RUN npm install puppeteer@1.10.0 express
# RUN apt install -y libcurl4-gnutls-dev libexpat1-dev gettext libz-dev librtmp-dev libxml2-dev libxslt-dev --no-install-recommends
# RUN apt install -y curl libatk-bridge2.0-0 libgtk-3-0 libopencc-dev opencc libpq-dev  gcc g++ --no-install-recommends


COPY requirements.txt /opt/pyspider/requirements.txt 
RUN pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip3 install --no-cache-dir -r /opt/pyspider/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/



ADD ./ /opt/pyspider


WORKDIR /opt/pyspider
RUN pip install -e .[all]

RUN rm -rf  ~/.cache/pip

RUN ln -s /opt/node/node_modules ./node_modules


ENTRYPOINT ["pyspider"]

EXPOSE 5000 23333 24444 25555 22222